home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / cfgfile.y < prev    next >
Encoding:
Lex Description  |  1996-03-30  |  13.5 KB  |  419 lines

  1. %{
  2. /*
  3.   SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  4.  
  5.   Copyright (C) 1995  Koen Gadeyne
  6.  
  7.   This program is free software; you can redistribute it and/or modify
  8.   it under the terms of the GNU General Public License as published by
  9.   the Free Software Foundation; either version 2 of the License, or
  10.   (at your option) any later version.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License
  18.   along with this program; if not, write to the Free Software
  19.   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22.   Based on earlier work done for svgalib by Stephen Lee.
  23. */
  24.  
  25. /****************************************************************************/
  26. /* C DECLARATIONS */
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "cfg_structs.h"
  30. #include "chipset.h"
  31. #include "messages.h"
  32. #include "misc.h"
  33. #include <sys/stat.h>
  34.  
  35. /* if VGA_CAN_DO_64KB is defined, 32k chars per screen are allowed */
  36. #ifdef VGA_CAN_DO_64KB
  37. #define MAXCHARS 32*1024
  38. #else
  39. #define MAXCHARS 16*1024
  40. #endif
  41.  
  42. /* stuff exported by the lexer */
  43. extern int yylex();
  44. extern int line_num;
  45.  
  46. int addmode(t_mode *mval);
  47. int addhsync(float min, float max);
  48. int addvsync(float min, float max);
  49.  
  50. void complete_modestruct(t_mode *mtp);
  51. t_mode *add_mode_data(char *name, float clock,
  52.                    int hds, int hss, int hse, int hde,
  53.                    int vds, int vss, int vse, int vde);
  54.  
  55. void check_path(char *fname, int line);
  56. void check_fontsize(int x, int y);
  57. void check_clock(float clk, char* descr, int line);
  58.  
  59. #define yyerror(s) PERROR(("%s on line %d in config file\n", (s), line_num));
  60.  
  61. %}
  62. %union {
  63.     float fval;            /* for returning floating-point values */
  64.     int ival;            /* integer values */
  65.     char *sval;            /* string values (malloc'd) */
  66.     t_mode *mval;        /* mode values (malloc'd) */
  67. }
  68.  
  69. /****************************************************************************/
  70. /* BISON DECLARATIONS */
  71.  
  72. %token MODELINE DIM TERMINALS UNDERLINE BORDERCOL
  73. %token CLOCKS DACSPEED MCLK REFCLK CURSOR
  74. %token RESETPROG CLOCKPROG HORIZSYNC VERTREFRESH
  75. %token FONTSELECT
  76.  
  77. %token <ival> FLAGS UNDERLINE INT
  78. %token <ival> HSYNC VSYNC
  79. %token <fval> FLOAT
  80.  
  81. %token <sval> QSTRING SMODELINE DFLTMODE
  82. %token <sval> STRING
  83. %token FONT FONTPROG FONTPATH
  84.  
  85. %token CHIPSET
  86. %token <ival> CHIPSETTYPE CLOCKCHIPTYPE OPTIONDEF
  87.  
  88. %type <mval> modeline
  89. %type <sval> font_sel
  90. %type <fval> num
  91.  
  92. %%
  93. lines: /* empty string */
  94.     | lines '\n'
  95.     | lines modeline '\n'            { addmode($2); complete_modestruct($2); }
  96.     | lines hsyncline '\n'
  97.     | lines vsyncline '\n'
  98.     | lines clocksline '\n'
  99.     | lines cursordef '\n'
  100.     | lines DFLTMODE QSTRING '\n'        { defaultmode = safe_strdup($3); }
  101.     | lines CLOCKCHIPTYPE '\n'        { clock_data.clockchiptype = $2; }
  102.     | lines DACSPEED num '\n'        {
  103.                                                 check_clock($3, "DacSpeed", line_num-1);
  104.                                                 clock_data.maxclock = (int)($3*1000);
  105.                                             }
  106.     | lines CHIPSETTYPE '\n'        {
  107.                                                 chipset = $2;
  108.                                                 /* if max clock not defined yet (DacSpeed line), assign chipset default */
  109.                                                 if (clock_data.maxclock==DEFAULT_MAXCLOCK)
  110.                                                   clock_data.maxclock=ChipsetData[chipset].maxclock;
  111.                                             }
  112.     | lines MCLK num '\n'            {
  113.                                                 check_clock($3, "MClk", line_num-1);
  114.                                                 clock_data.mclk = (int)($3*1000);
  115.                                             }
  116.     | lines REFCLK num '\n'            {
  117.                                                 check_clock($3, "RefClk", line_num-1);
  118.                                                 clock_data.refclk = (int)($3*1000);
  119.                                             }
  120.     | lines OPTIONDEF '\n'            { OFLG_SET($2); }
  121.     | lines UNDERLINE INT'\n'        {
  122.                                                 if (($3<1) || ($3>32))
  123.                                                   PERROR(("Underline position %d out of bounds [1..32] on line %d in config file\n", $3, line_num-1));
  124.                                                 underline_pos = $3;
  125.                                             }
  126.     | lines BORDERCOL INT'\n'        {
  127.                                                 if (($3<0) || ($3>255))
  128.                                                   PERROR(("BorderColor %d out of bounds [0..255] on line %d in config file\n", $3, line_num-1));
  129.                                                 bordercolor = $3; }
  130.     | lines RESETPROG QSTRING '\n'        {
  131.                                                 check_path($3, line_num+1);
  132.                                                 resetprogpath = safe_strdup($3);
  133.                                             }
  134.     | lines CLOCKPROG QSTRING '\n'        {
  135.                                                 check_path($3, line_num+1);
  136.                                                 clock_data.ck_prog_path = safe_strdup($3);
  137.                                             }
  138.     | lines FONTPROG QSTRING '\n'        {
  139.                                                 check_path($3, line_num+1);
  140.                                                 font_data.fontprogpath = safe_strdup($3);
  141.                                             }
  142.     | lines FONTPATH QSTRING '\n'        {
  143.                                                 check_path($3, line_num+1);
  144.                                                 font_data.fontpath = safe_strdup($3);
  145.                                             }
  146.     | lines term_line '\n'
  147.     | lines font_sel '\n'
  148.     | lines QSTRING '\n'                    {
  149.                                                 printf("%s\n",$2);
  150.                                             }
  151. ;
  152.  
  153. /* included so that float values can also be specified in the form of an INT */
  154. num:    FLOAT
  155.     | INT { $$ = $1; }
  156. ;
  157.  
  158. modeline: MODELINE QSTRING num INT INT INT INT INT INT INT INT
  159.         {
  160.             $$ = add_mode_data($2,$3,$4,$5,$6,$7,$8,$9,$10,$11);
  161.         }
  162.     | SMODELINE num INT INT INT INT INT INT INT INT
  163.     { 
  164.             $$ = add_mode_data($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);
  165.     }
  166.     | modeline HSYNC
  167.     {
  168.         $$ = $1;
  169.         $$->hpol=$2;
  170.     }
  171.     | modeline VSYNC
  172.     {
  173.         $$ = $1;
  174.         $$->vpol=$2;
  175.     }
  176.     | modeline FLAGS
  177.     {
  178.         $$ = $1;
  179.         MOFLG_SET($$,$2);
  180.     }
  181.     | modeline FONT INT DIM INT
  182.     { 
  183.         $$ = $1;
  184.         check_fontsize($3,$5);
  185.         $$->FontWidth = $3;
  186.         $$->FontHeight = $5;
  187.     }
  188. ;
  189.  
  190. font_sel: FONTSELECT INT DIM INT
  191.     {
  192.           PERROR(("Syntax error on line %d in config file.\n"\
  193.                   "Possible cause: the syntax of the FontSelect lines has changed!\n"\
  194.                   "See the TextConfig(5) manual file for details.\n", line_num));
  195.     }
  196.     | FONTSELECT QSTRING
  197.     {
  198.         $$ = safe_strdup($2);
  199.     }
  200.     | font_sel INT DIM INT 
  201.     {
  202.         $$ = $1;
  203.         check_fontsize($2, $4);
  204.         font_data.font_table[$2-8][$4-1] = $1;
  205.     }
  206. ;
  207.  
  208. hsyncline: HORIZSYNC
  209.     | hsyncline num '-' num        { addhsync($2, $4); }
  210.     | hsyncline num            { addhsync($2, $2); }
  211.     | hsyncline ',' num '-' num    { addhsync($3, $5); }
  212.     | hsyncline ',' num        { addhsync($3, $3); }
  213. ;
  214.  
  215. vsyncline: VERTREFRESH
  216.     | vsyncline num '-' num        { addvsync($2, $4); }
  217.     | vsyncline num            { addvsync($2, $2); }
  218.     | vsyncline ',' num '-' num    { addvsync($3, $5); }
  219.     | vsyncline ',' num        { addvsync($3, $3); }
  220. ;
  221.  
  222. cursordef: CURSOR
  223.     | cursordef INT '-' INT        { 
  224.                                       if ($2<$4)
  225.                                         { cursor_start = $2; cursor_end = $4;}
  226.                                       else
  227.                                         { cursor_start = $4; cursor_end = $2;}
  228.                                     }
  229.     | cursordef INT            { cursor_start = $2; cursor_end = $2; }
  230. ;
  231.  
  232. clocksline: CLOCKS
  233.     | clocksline num         {
  234.                                             check_clock($2, "Clock", line_num);
  235.                                         clock_data.clocks[clock_data.num_clocks++] = (int) ($2*1000);
  236.                                     }
  237. ;
  238.  
  239. term_line: TERMINALS
  240.     | term_line QSTRING         {
  241.                                       t_terminals *p_t;
  242.                                       char *full_path;
  243.                                       
  244.                                           full_path = safe_malloc(strlen($2)+6);
  245.                                       strcpy(full_path, "/dev/");
  246.                                       strcat(full_path, $2);
  247.                                       check_path(full_path, line_num);
  248.  
  249.                                           p_t = safe_malloc(sizeof(t_terminals));
  250.                                           p_t->name = full_path;
  251.                                           p_t->next = p_terminals;
  252.                                           p_terminals = p_t;
  253.                                         }
  254. ;
  255.  
  256. %%
  257. /****************************************************************************/
  258. /* ADDITIONAL C CODE */
  259.  
  260. extern FILE *yyin;
  261.  
  262. void yy_check_int_range(int cvalue, int lmin, int lmax, char *descstr, char *remark)
  263. {
  264.   if (cvalue<lmin || cvalue>lmax)
  265.     PERROR(("%s = %d out of range [%d..%d] in config file on line %d%s\n",\
  266.              descstr, cvalue, lmin, lmax, line_num, remark ? remark : ""));
  267. }
  268.  
  269. int addmode(t_mode *mval)
  270. {
  271.     mval->next = text_mode_list;
  272.     text_mode_list = mval;
  273.  
  274.     return 0;
  275. }
  276.  
  277. /* fill in some values that are NOT in the mode line, like H/V freq, XxY size, ...*/
  278. void complete_modestruct(t_mode *mtp)
  279. {
  280.     mtp->rows = mtp->VDisplay / mtp->FontHeight;
  281.     mtp->cols = (mtp->HDisplay / 8) & 0xFFFFFFFE; /* must be multiple of 2 in VGA byte-mode adressing */
  282.     mtp->VDisplay = mtp->FontHeight * mtp->rows;  /* make mtp->VDisplay integer multiple of mtp->FontHeight */
  283.     
  284.     if (mtp->rows * mtp->cols > MAXCHARS)
  285.       PERROR(("Maximum of %d characters exceeded (%dx%d = %d) on modeline on line %d\n.", \
  286.                MAXCHARS, mtp->cols, mtp->rows, mtp->cols * mtp->rows));
  287.  
  288.     if (MOFLG_ISSET(mtp,ATTR_DOUBLESCAN))
  289.     {
  290.       mtp->VDisplay *= 2;
  291.       mtp->VSyncStart *= 2;
  292.       mtp->VSyncEnd *= 2;
  293.       mtp->VTotal *= 2;
  294.     }
  295.  
  296.     mtp->hfreq = (mtp->pixelClock*1000)/( ((int)(mtp->HTotal / 8)) * mtp->FontWidth);
  297.     mtp->vfreq = (mtp->hfreq*1000)/mtp->VTotal;
  298.     if (MOFLG_ISSET(mtp,ATTR_INTERLACE)) mtp->vfreq *= 2;
  299. }
  300.  
  301.  
  302. t_mode *add_mode_data(char *name, float clock,
  303.                    int hds, int hss, int hse, int hde,
  304.                    int vds, int vss, int vse, int vde)
  305.     t_mode *mtp;
  306.  
  307.    /*
  308.     * Do some SEVERE error checking on the text mode string timings!
  309.     * the ranges are somewhat randomly chosen. Need to study REAL hardware limits for this...
  310.     */
  311.     yy_check_int_range(hds, 16, 4096, "active pixels", NULL);
  312.     yy_check_int_range(hss, hds, 4096, "start of H-sync", NULL);
  313.     yy_check_int_range(hse, hss+1, hss+(32*8), "end of H-sync", " (Max Hsync width = 256 pixels)");
  314.     yy_check_int_range(hde, hse, 4096, "total pixels", NULL);
  315.  
  316.     yy_check_int_range(vds, 16, 4096, "active lines", NULL);
  317.     yy_check_int_range(vss, vds, 4096, "start of V-sync", NULL);
  318.     yy_check_int_range(vse, vss+1, vss+16, "end of V-sync", " (Max Vsync width = 16 lines)");
  319.     yy_check_int_range(vde, vse, 4096, "total lines", NULL);
  320.  
  321.     /* mode has passed initial checks. enter it into the data base */
  322.     mtp = safe_malloc(sizeof(t_mode));
  323.  
  324.     mtp->name = safe_strdup(name);
  325.       
  326.     mtp->pixelClock = clock * 1000;
  327.     mtp->HDisplay = hds;
  328.     mtp->HSyncStart = hss;
  329.     mtp->HSyncEnd = hse;
  330.     mtp->HTotal = hde;
  331.     mtp->VDisplay = vds;
  332.     mtp->VSyncStart = vss;
  333.     mtp->VSyncEnd = vse;
  334.     mtp->VTotal = vde;
  335.  
  336.     mtp->flags = 0;        /* default */
  337.     mtp->FontWidth = 8;    /* default */
  338.     mtp->FontHeight = 16;  /* default */
  339.  
  340.     /* Auto sync polarity -- will be overridden by specified polarities on mode line */
  341.     if (vds < 400)      { mtp->hpol = POS ; mtp->vpol = NEG; }
  342.     else if (vds < 480) { mtp->hpol = NEG ; mtp->vpol = POS; }
  343.     else if (vds < 768) { mtp->hpol = NEG ; mtp->vpol = NEG; }
  344.     else                { mtp->hpol = POS ; mtp->vpol = POS; }
  345.        
  346.     return mtp;
  347. }
  348.  
  349.  
  350. t_mon_timing* add_sync(float min, float max)
  351. {
  352.     t_mon_timing *tim;
  353.  
  354.     if ((min<5.0) || (min>200.0)) PERROR(("Sync range value %.3f out of bounds on line %d of config file\n", min, line_num));    
  355.     if ((max<5.0) || (max>200.0)) PERROR(("Sync range value %.3f out of bounds on line %d of config file\n", max, line_num));    
  356.  
  357.     tim = safe_malloc(sizeof(t_mon_timing));
  358.  
  359.     if (min<=max)
  360.     {
  361.        tim->low_limit = min*1000;
  362.        tim->high_limit = max*1000;
  363.     }
  364.     else
  365.     {
  366.        tim->low_limit = max*1000;
  367.        tim->high_limit = min*1000;
  368.     }
  369.     return tim;
  370. }
  371.  
  372. int addhsync(float min, float max)
  373. {
  374.     t_mon_timing *tim;
  375.  
  376.     tim = add_sync(min,max);
  377.     tim->next = h_mon_limits;
  378.     h_mon_limits = tim;
  379.  
  380.     return 0;
  381. }
  382.  
  383. int addvsync(float min, float max)
  384. {
  385.     t_mon_timing *tim;
  386.  
  387.     tim = add_sync(min,max);
  388.     tim->next = v_mon_limits;
  389.     v_mon_limits = tim;
  390.  
  391.     return 0;
  392. }
  393.  
  394. void check_path(char *fname, int line)
  395. {
  396.     struct stat fstatus;
  397.     char *cp;
  398.     
  399.     cp = safe_strdup(fname);
  400.     cp = strtok(cp," ");
  401.     
  402.     if (stat(cp, &fstatus))
  403.       PERROR(("Path `%s' specified on line %d in config file does not exist\n", cp, line));
  404. }
  405.  
  406. void check_fontsize(int x, int y)
  407. {
  408.     if ((x<8) || (x>9)) PERROR(("Illegal font width %d on line %d in config file\n", x, line_num));
  409.     if ((y<1) || (y>32)) PERROR(("Illegal font height %d on line %d in config file\n", y, line_num));
  410. }
  411.  
  412. void check_clock(float clk, char* descr, int line)
  413. {
  414.     if ((clk<MIN_CLOCK) || (clk>MAX_CLOCK))
  415.       PERROR(("%s value %.3f out of bounds on line %d in config file\n", descr, clk, line));
  416. }
  417.  
  418.